function a(a, t, o) {
    return t in a ? Object.defineProperty(a, t, {
        value: o,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : a[t] = o, a;
}

var t = require("../../utils/api.js"), o = getApp(), e = require("../../wxParse/wxParse.js");

Page({
    data: a({
        showrule: !1,
        nowTime: Date.parse(new Date()) / 1e3,
        showLoding: !0,
        showlodingmore: {
            showMore: !0,
            noMore: !1
        },
        showSuccesstipInfo: {
            showSuccesstip: !0,
            title: "已加入购物车",
            type: !0
        },
        showCount: 10,
        mid: !1,
        default_small_img: o.globalData.default_small_img,
        playBtn: "/images/playvideo.png",
        maxpage: 2
    }, "showLoding", !1),
    onLoad: function(a) {
        var n = this;
        console.log(n.data.nowTime), t.plsugins({
            openid: o.globalData.openid,
            op: "sign"
        }).then(function(a) {
            if (console.log(a), 0 == a.code) {
                for (var t = 0; t < a.data.data.data.length; t++) if (n.data.nowTime - a.data.data.data[t].time_chenk > 0 && n.data.nowTime - a.data.data.data[t].time_chenk < 86400) {
                    var o = a.data.data.data[t].time_chenk;
                    n.setData({
                        todayInfo: a.data.data.data[t]
                    }), console.log(n.data.todayInfo);
                }
                console.log(n.data.todayInfo), n.setData({
                    info: a.data.data,
                    checkinfo: a.data.data.data,
                    today: o
                }), e.wxParse("article", "html", a.data.data.rule, n, 5);
            } else wx.showToast({
                title: "还没有开启积分签到哦！",
                icon: "none",
                image: "",
                duration: 3e3,
                mask: !0,
                success: function(a) {},
                fail: function(a) {},
                complete: function(a) {}
            }), n.setData({
                noOpen: !0
            });
        }), t.getCartNum({
            openid: o.globalData.openid
        }).then(function(a) {
            console.log(a.data), n.setData({
                carnum: a.data
            });
        });
        var s = {
            openid: o.globalData.openid,
            page: 1
        };
        console.log(s), t.GoodsInfoRecommend(s).then(function(a) {
            console.log(a), n.setData({
                suggestGoods: a.data.data,
                othergoods: a.data,
                page: 1,
                showLoding: !0
            });
        });
    },
    showrule: function() {
        this.setData({
            showrule: !0
        });
    },
    closeshowCopy: function() {
        this.setData({
            showrule: !1
        });
    },
    showdetail: function() {
        wx.navigateTo({
            url: "/pages/checkIn/checkinDetail"
        });
    },
    checked: function() {
        var e = this, n = Date.parse(new Date()) / 1e3;
        if (e.data.noOpen) wx.showToast({
            title: "没有开启积分签到哦！等开启后再来签到吧",
            icon: "none",
            image: "",
            duration: 3e3,
            mask: !0,
            success: function(a) {},
            fail: function(a) {},
            complete: function(a) {}
        }); else {
            for (var s in e.data.checkinfo) if (e.data.nowTime - e.data.checkinfo[s].time_chenk > 0 && e.data.nowTime - e.data.checkinfo[s].time_chenk < 86400) {
                var i = "checkinfo[" + s + "].chenk", d = e.data.checkinfo[s].chenk;
                console.log(e.data.checkinfo[s]);
            }
            t.plsugins({
                openid: o.globalData.openid,
                op: "sign",
                in: "sign_in",
                time: n
            }).then(function(t) {
                if (console.log(t), 0 == t.data.code) {
                    var o;
                    wx.showToast({
                        title: e.data.info.in + "成功,获得" + t.data.data.money + e.data.info.integral,
                        icon: "none",
                        duration: 2e3
                    }), e.setData((o = {}, a(o, i, !0), a(o, "todayInfo.chenk", !1), a(o, "is_checked", !0), 
                    o)), e.onLoad();
                } else d ? wx.showToast({
                    title: "您今天已经" + e.data.info.in + "过一次了",
                    icon: "none",
                    duration: 2e3
                }) : wx.showToast({
                    title: e.data.info.in + "失败",
                    icon: "none",
                    duration: 2e3
                });
            });
        }
    },
    add: function(e) {
        var n = this, s = n.data.suggestGoods, i = e.currentTarget.dataset.id, d = {
            gid: i,
            num: 1,
            openid: o.globalData.openid
        };
        console.log(s);
        for (var c = 0; c < s.length; c++) {
            var g = "suggestGoods[" + c + "].curGoodsNum", r = n.data.suggestGoods[c].curGoodsNum, l = n.data.suggestGoods[c].g_limit_num, u = n.data.suggestGoods[c].num;
            u = parseInt(u), l = parseInt(l), r = parseInt(r);
            var p = Math.min(l, u);
            if (s[c].g_id == i) {
                if (console.log(r), r < p && l > 0) n.setData(a({}, g, r + 1)); else if (r < u && 0 == l) n.setData(a({}, g, r + 1)); else {
                    if (r >= l) return console.log(l, r), void wx.showToast({
                        title: "商品限购" + l + "件哦",
                        icon: "none",
                        duration: 2e3
                    });
                    if (r >= u) return void wx.showToast({
                        title: "商品数量没有那么多了",
                        icon: "none",
                        duration: 2e3
                    });
                }
                break;
            }
        }
        t.addCart(d).then(function(a) {
            console.log(a.data), 0 == a.errno ? (console.log(0), n.successtip(), wx.setStorageSync("cartnum", a.data.count), 
            n.setData({
                carnum: a.data.count
            }), 0 != a.data.count ? (wx.showTabBarRedDot({
                index: 2
            }), wx.setTabBarBadge({
                index: 2,
                text: a.data.count + ""
            })) : wx.hideTabBarRedDot({
                index: 2
            })) : wx.showToast({
                title: a.message,
                icon: "none",
                duration: 2e3
            });
        });
    },
    onCloseButton: function(a) {
        this.setData({
            specShow: !this.data.specShow
        });
    },
    addSpec: function(a) {
        console.log(a);
        var e = this, n = o.globalData.openid, s = a.currentTarget.dataset.id, i = a.currentTarget.dataset.atid;
        t.GetSpecInfo({
            openid: n,
            id: s
        }).then(function(a) {
            if (0 == a.errno) {
                var o = [], s = [];
                console.log(a.data.spec);
                for (var d in a.data.spec) {
                    var c = [], g = [];
                    s[d] = {
                        id: a.data.spec[d].id,
                        subSpec: a.data.spec[d].item[0].gsi_id
                    };
                    for (var r in a.data.spec[d].item) c[r] = a.data.spec[d].item[r].gsi_title, g[r] = a.data.spec[d].item[r].gsi_id;
                    o[d] = {
                        id: a.data.spec[d].id,
                        name: a.data.spec[d].title,
                        stem: c,
                        stem_id: g
                    };
                }
                for (var l = "", d = s.length - 1; d >= 0; d--) l += "," + s[d].subSpec;
                console.log(l, a.data.goods.g_id), t.GetSpecDeatail({
                    openid: n,
                    id_str: l,
                    gid: a.data.goods.g_id
                }).then(function(t) {
                    if (console.log(t), 0 == t.errno) {
                        var n = t.data.ggo_market_price.split("."), d = a.data.goods.g_limit_num <= 0 ? t.data.ggo_stock : parseInt(a.data.goods.g_limit_num) < parseInt(t.data.ggo_stock) ? a.data.goods.g_limit_num : t.data.ggo_stock, c = {
                            id: a.data.goods.g_id,
                            name: a.data.goods.g_name,
                            photo: a.data.goods.g_icon,
                            specInfo: t.data.ggo_title,
                            price: n,
                            oldPrice: t.data.ggo_old_price,
                            num: 1,
                            popup: o,
                            count: t.data.ggo_stock,
                            limit: d,
                            is_limit: a.data.goods.g_limit_num,
                            ggo_id: t.data.ggo_id
                        };
                        e.setData({
                            specDetail: c,
                            specShow: !e.data.specShow,
                            specDefault: s,
                            atid: i
                        });
                    } else wx.showToast({
                        title: a.message,
                        icon: "none"
                    });
                });
            } else wx.showToast({
                title: a.message,
                icon: "none"
            });
        });
    },
    specAddCart: function(e) {
        for (var n = this, s = e.currentTarget.dataset.id, i = e.currentTarget.dataset.optionid, d = e.currentTarget.dataset.num, c = e.currentTarget.dataset.atid, g = n.data.suggestGoods, r = 0; r < g.length; r++) {
            var l = "suggestGoods[" + r + "].curGoodsNum", u = n.data.suggestGoods[r].curGoodsNum;
            if (g[r].g_id == s) {
                if (!(0 == g[r].g_limit_num || u < g[r].g_limit_num)) return void wx.showToast({
                    title: "本商品限购" + g[r].g_limit_num + "件",
                    icon: "none",
                    duration: 2e3
                });
                n.setData(a({}, l, parseInt(u) + 1));
                break;
            }
        }
        t.SpecAddCart({
            openid: o.globalData.openid,
            gid: s,
            ggoid: i,
            num: d,
            at_id: c
        }).then(function(a) {
            0 == a.errno ? (n.successtip(), 0 != a.data.count ? (wx.showTabBarRedDot({
                index: 2
            }), wx.setTabBarBadge({
                index: 2,
                text: a.data.count + ""
            })) : wx.hideTabBarRedDot({
                index: 2
            }), n.setData({
                specShow: !1,
                carnum: a.data.count
            }), wx.setStorageSync({
                key: "cartnum",
                data: parseInt(a.data.count)
            })) : wx.showToast({
                title: a.message,
                icon: "none",
                duration: 2e3
            });
        });
    },
    popup: function(a) {
        for (var e = this, n = a.currentTarget.dataset.id, s = a.currentTarget.dataset.subid, i = e.data.specDefault, d = "", c = i.length - 1; c >= 0; c--) i[c].id == n && (i[c].subSpec = s, 
        e.setData({
            specDefault: i
        })), d += "," + i[c].subSpec;
        var g = o.globalData.openid, r = e.data.specDetail;
        t.GetSpecDeatail({
            openid: g,
            id_str: d,
            gid: r.id
        }).then(function(a) {
            if (0 == a.errno) {
                var t = a.data.ggo_market_price.split("."), o = r.is_limit <= 0 ? a.data.ggo_stock : parseInt(r.is_limit) < parseInt(a.data.ggo_stock) ? r.is_limit : a.data.ggo_stock;
                r.specInfo = a.data.ggo_title, r.price = t, r.oldPrice = a.data.ggo_old_price, r.count = a.data.ggo_stock, 
                r.limit = o, r.ggo_id = a.data.ggo_id, e.setData({
                    specDetail: r
                });
            } else wx.showToast({
                title: res.message,
                icon: "none"
            });
        });
    },
    onReachBottom: function(a) {
        console.log(a);
        var e = this;
        e.setData({
            "showlodingmore.showMore": !0,
            "showlodingmore.noMore": !1
        });
        var n = e.data.page;
        if (console.log(n), n < e.data.maxpage) {
            var s = {
                openid: o.globalData.openid,
                page: n + 1
            }, i = e.data.suggestGoods;
            console.log(s), t.GoodsInfoRecommend(s).then(function(a) {
                console.log(a);
                for (var t = 0; t < a.data.data.length; t++) i.push(a.data.data[t]);
                e.setData({
                    suggestGoods: i,
                    "showlodingmore.showMore": !1,
                    "showlodingmore.noMore": !1,
                    page: e.data.page + 1
                });
            });
        } else e.setData({
            "showlodingmore.showMore": !1,
            "showlodingmore.noMore": !1
        });
    },
    successtip: function() {
        arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
        var t = this;
        t.setData(a({}, "showSuccesstipInfo.showSuccesstip", !t.data.showSuccesstipInfo.showSuccesstip)), 
        console.log(t.data.showSuccesstipInfo.showSuccesstip), setTimeout(function() {
            t.setData(a({}, "showSuccesstipInfo.showSuccesstip", !t.data.showSuccesstipInfo.showSuccesstip));
        }, 1300);
    }
});